from tbody_builder import TableBodyBuilder

data = list()
data.append(['k', '2', '3', 1])
data.append(['k', '2 - 1', '3 - 1', '-'])
data.append(['k', '2 - 1', '3 - 1', 4])
data.append(['k', '2 - 2', '3 - 1', 5])
data.append(['k', '2 - 2', '3 - 2', 5])
data.append(['k1', '2', '3', 1])
data.append(['k1', '2 - 1', '3 - 1', '-'])
data.append(['k1', '2 - 1', '3 - 1', 4])
data.append(['k1', '2 - 2', '3 - 1', 5])
data.append(['k1', '2 - 2', '3 - 2', 5])


# 如果需要某一列单元格不合并，可以和某个数据不重复的列做related

def sytle_test(value):
    if not isinstance(value, int):
        return ''
    elif int(value) < 5:
        return 'bgcolor="yellow"'
    else:
        return 'bgcolor="red"'


style_func = {
    3: sytle_test
}

obj = TableBodyBuilder(data, [[1, 2]], style_func)
res = obj.generate_table()

html = ['<html><table border="1"><thead><th>first</th><th>second</th><th>third</th><th>fourth</th></thead>']
html.append(res)
html.append('</table></html>')

with open('test.html', mode='w+', encoding='utf8') as fp:
    fp.write(''.join(html))
